﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace TechMadeira.Data.Classes
{
    public class Product : Semantic, IProduct
    {
        #region Fields
        [XmlArray(ElementName = "Categories"),XmlArrayItem("Category",typeof(ProductCategory))]
        private List<IProductCategory> mCategories = new List<IProductCategory>();
        #endregion

        public Product()
        {
            Categories = new List<IProductCategory>();
        }

        public string Name { get; set; }
        public string Description { get; set; }
        public double Price { get; set; }

        [XmlIgnore()]
        public IEnumerable<IProductCategory> Categories { get; private set; }
        public void Append( IProductCategory aCategory )
        {
            if ( Categories.Contains( aCategory ) ) return;
            ((ICollection<IProductCategory> )Categories).Add( aCategory );
        }

        public void Remove( IProductCategory aCategory )
        {
            if ( ! Categories.Contains( aCategory ) ) return;
            ( (ICollection<IProductCategory>) Categories ).Remove( aCategory );
        }
    }
}
